-- auto_fight
-- create by cheny3
-- 调用格子的auto_fight

return {
    -- 判断
    canTrigger = function(args)
        local specialGrids = AutoFightM.getData()["specialGrids"];
        if specialGrids and #specialGrids > 0 then
            return true;
        end
        return false;
    end,

    -- 触发
    trigger = function(args)
        local specialGrids = AutoFightM.getData()["specialGrids"];
        if not specialGrids or #specialGrids <= 0 then
            return false;
        end

        for _, pos in pairs(specialGrids) do
            local grid = DungeonM.DungeonM.getGridByPos(pos);
            local mod = DungeonM.getModule(grid.class);
            -- 可能有报错，用catch
            local ret = catch(function() return mod.autoFight(grid); end);
            if ret then
                cclog("auto fight: " .. pos);
                EventMgr.fire(event.PLAYER_MOVE, pos);
                return true;
            end
        end
        return false;
    end,
};
